home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’93 / sort / Source / sortmain.c < prev    next >
C/C++ Source or Header  |  1993-06-17  |  4KB  |  210 lines

  1. /*****
  2.  * sortmain.c
  3.  *
  4.  *
  5.  *
  6.  *****/
  7. #include <Quickdraw.h>
  8. #include <Windows.h>
  9. #include <Dialogs.h>
  10. #include <Memory.h>
  11. #include <Fonts.h>
  12. #include <Events.h>
  13. #include <OSEvents.h>
  14. #include <Menus.h>
  15. #include <Desk.h>
  16. #include <ToolUtils.h>
  17. #include <TextEdit.h>
  18. #include <DiskInit.h>
  19.  
  20. #ifdef THINK_C
  21. #include <Think.h>
  22. #endif
  23.  
  24.  
  25. #include "sortMenus.h"
  26. #include "sortWindow.h"
  27. #include "sort.h"
  28. #include "notif.h"
  29. #include "acur.h"
  30.  
  31. Boolean done;
  32.  
  33. #define ACUR_ID 128
  34.  
  35. extern    WindowPtr    sortWindow;
  36. extern    Rect        dragRect;
  37.  
  38. void InitMacintosh(void);
  39. void HandleMouseDown (EventRecord    *theEvent);
  40.  
  41. /****
  42.  * InitMacintosh()
  43.  *
  44.  * Initialize all the managers & memory
  45.  *
  46.  ****/
  47.  
  48. void InitMacintosh(void)
  49.  
  50. {
  51.     MaxApplZone();
  52. #ifdef THINK_C
  53.     InitGraf(&thePort);
  54. #else /* applec */
  55.     InitGraf(&qd.thePort);
  56. #endif /* applec */
  57.     qd.randSeed = TickCount();
  58.     InitFonts();
  59.     FlushEvents(everyEvent, 0);
  60.     InitWindows();
  61.     InitMenus();
  62.     TEInit();
  63.     InitDialogs(0L);
  64.     InitCursor();
  65.     Initacur(ACUR_ID);
  66. }
  67. /* end InitMacintosh */
  68.  
  69.  
  70. /****
  71.  * HandleMouseDown (theEvent)
  72.  *
  73.  *    Take care of mouseDown events.
  74.  *
  75.  ****/
  76.  
  77. void HandleMouseDown (EventRecord    *theEvent)
  78.  
  79. {
  80.     WindowPtr    theWindow;
  81.     int            windowCode = FindWindow (theEvent->where, &theWindow);
  82.     
  83.     switch (windowCode)
  84.       {
  85.       case inSysWindow: 
  86.         SystemClick (theEvent, theWindow);
  87.         break;
  88.         
  89.       case inMenuBar:
  90.               AdjustMenus();
  91.             SetCursor(&qd.arrow);
  92.             HandleMenu(MenuSelect(theEvent->where));
  93.         break;
  94.         
  95.       case inDrag:
  96.           if (theWindow == sortWindow)
  97.             DragWindow(sortWindow, theEvent->where, &dragRect);
  98.             break;
  99.             
  100.       case inContent:
  101.           if (theWindow == sortWindow)
  102.             {
  103.             if (theWindow != FrontWindow())
  104.               SelectWindow(sortWindow);
  105.             else
  106.               InvalRect(&sortWindow->portRect);
  107.             }
  108.           break;
  109.           
  110.       case inGoAway:
  111.           if (theWindow == sortWindow && 
  112.               TrackGoAway(sortWindow, theEvent->where))
  113.           HideWindow(sortWindow);
  114.             break;
  115.       }
  116. }
  117. /* end HandleMouseDown */
  118.  
  119.  
  120. /****
  121.  * HandleEvent()
  122.  *
  123.  *        The main event dispatcher. This routine should be called
  124.  *        repeatedly (it  handles only one event).
  125.  *
  126.  *****/
  127.  
  128. void HandleEvent(void)
  129.  
  130. {
  131.     int            ok;
  132.     EventRecord    theEvent;
  133.  
  134.     SystemTask ();        /* Handle desk accessories */
  135.     
  136.     ok = WaitNextEvent (everyEvent, &theEvent, 1L, NULL);
  137.     if (ok)
  138.       switch (theEvent.what)
  139.         {
  140.         case mouseDown:
  141.             HandleMouseDown(&theEvent);
  142.             break;
  143.             
  144.         case keyDown: 
  145.         case autoKey:
  146.             if ((theEvent.modifiers & cmdKey) != 0) {
  147.                   AdjustMenus();
  148.                 SetCursor(&qd.arrow);
  149.                   HandleMenu(MenuKey((char) (theEvent.message & charCodeMask)));
  150.             }
  151.             break;
  152.             
  153.         case updateEvt:
  154.             BeginUpdate(sortWindow);
  155.             DrawSort(((WindowPeek) sortWindow)->hilited);
  156.             EndUpdate(sortWindow);
  157.             break;
  158.             
  159.         case activateEvt:
  160.             break;
  161.  
  162.         case diskEvt:
  163.             if ( HiWord(theEvent.message) != noErr ) {
  164.                 Point aPoint;
  165.                 
  166.                 SetPt(&aPoint, 100, 199);
  167.                 DIBadMount(aPoint, theEvent.message);
  168.             }
  169.             break;
  170.             
  171.         case osEvt:
  172.             switch ((theEvent.message >> 24) & 0x0FF) {        /* high byte of message */
  173.                 case suspendResumeMessage:        /* suspend/resume is also an activate/deactivate */
  174.                     gInBackground = (theEvent.message & resumeFlag) == 0;
  175.                     break;
  176.                     
  177.                 default:
  178.                     break;
  179.             }
  180.  
  181.  
  182.         }
  183. }
  184. /* end HandleEvent */
  185.  
  186.  
  187. /*****
  188.  * main()
  189.  *
  190.  *    This is where everything happens
  191.  *
  192.  *****/
  193.  
  194. main()
  195. {
  196.     InitMacintosh();
  197.     SetUpMenus();
  198.     SetUpWindow();
  199.       if (init_data(numdataitems) != noErr) {
  200.             numdataitems = 2;
  201.         height=((((windowBounds.bottom - windowBounds.top) - numdataitems) -5)) / (numdataitems + 1);
  202.             init_data(numdataitems);
  203.       }
  204.     sorting = false;
  205.     gInBackground = false;
  206.     done = false;
  207.     for (;done == false;)
  208.         HandleEvent();
  209. }
  210. /* end main */